package com.example.qingyiapp.ui.activity.fragment.fragment_FrientUI.childfragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.qingyiapp.service.entify.IntrodutioBean;
import com.example.qingyiapp.R;
import com.example.qingyiapp.service.entify.Databean;
import com.example.qingyiapp.service.entify.FindFriend;
import com.example.qingyiapp.service.entify.FindTJBean;
import com.example.qingyiapp.service.entify.FriendSquareBean;
import com.example.qingyiapp.service.entify.FriendXxBean;
import com.example.qingyiapp.service.presenter.PersenterMannaer;
import com.example.qingyiapp.service.view.IChildView;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv2;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_lv3;
import com.example.qingyiapp.ui.activity.fragment.fragment_AddressUI.address_bean.JavaBean_msg;
import com.example.qingyiapp.ui.activity.fragment.fragment_FrientUI.Adapter.FindfriendADpter;
import com.example.qingyiapp.ui.activity.fragment.fragment_FrientUI.Entify.Findfriendentity;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @author ：created by 申德丰
 * Create Date ：2019/9/19 16:12
 * Package_Name : QingYiApp
 */
public class FindFriend_chlid_fragmnet extends Fragment {

    @BindView(R.id.find_friend_xrecyclerview)
    XRecyclerView findFriendXrecyclerview;
    Unbinder unbinder;
    ArrayList<Findfriendentity> findfriendentities=new ArrayList<>();

    IChildView iChildView=new IChildView() {
        @Override
        public void onSuccess(Databean s) {

        }

        @Override
        public void onError(String error) {

        }

        @Override
        public void ongetAddress_lvData(JavaBean_lv javaBean_lv) {

        }

        @Override
        public void ongetAddress_lvData2(JavaBean_lv2 javaBean_lv2) {

        }

        @Override
        public void ongetAddress_lvData3(JavaBean_lv3 javaBean_lv3) {

        }

        @Override
        public void ongetAddress_lvData4(JavaBean_msg javaBean_lv4) {

        }

        @Override
        public void ongetfriendSquareBean(FriendSquareBean friendSquareBean) {

        }

        @Override
        public void ongetfindfriend(FindFriend findFriend) {

            List<FindFriend.DataBean> data = findFriend.getData();


            for (int i = 0; i < data.size(); i++) {
                FindFriend.DataBean dataBean = data.get(i);
                String name = dataBean.getName();
                String usercover = dataBean.getUsercover();
                String description = dataBean.getDescription();


                Findfriendentity findfriendentity=new Findfriendentity(name,usercover,description);
                findfriendentities.add(findfriendentity);
            }
            findfriendADpter.notifyDataSetChanged();

        }

        @Override
        public void getjsonstring(FindTJBean s) {

        }

        @Override
        public void getfriendxxbean(FriendXxBean friendXxBean) {

        }

        @Override
        public void getIntrodution1(IntrodutioBean introdutioBean) {

        }
    };
    private PersenterMannaer persentermanager;

    private int page=0;
    private FindfriendADpter findfriendADpter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_findfriend_child_ui, container, false);
        unbinder = ButterKnife.bind(this, inflate);

        persentermanager =new PersenterMannaer(getContext(),"http://www.iqingyi.com/");
        persentermanager.onCreate();
        persentermanager.attchview(iChildView);
        persentermanager.getfindfriend(page,20);

        findfriendADpter = new FindfriendADpter(findfriendentities, getContext());
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        findFriendXrecyclerview.setLayoutManager(linearLayoutManager);
        View view=View.inflate(getContext(),R.layout.findfriend_xr_head,null);
        findFriendXrecyclerview.addHeaderView(view);
        findFriendXrecyclerview.setAdapter(findfriendADpter);

        findFriendXrecyclerview.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                persentermanager.getfindfriend(page,20);
                findFriendXrecyclerview.refreshComplete();
            }

            @Override
            public void onLoadMore() {
              page+=20;
                persentermanager.getfindfriend(page,20);
                findFriendXrecyclerview.loadMoreComplete();

            }
        });

        return inflate;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
